package wang;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ticTacToe extends JFrame{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8235769220241752988L;
	private JLabel text1;
	private JButton button1;
	private JButton playButtons[][] = new JButton[3][3];
	private JButton button2;
	public ticTacToe(){
		this.setTitle("My game");
	      this.setSize(600,400);
	      this.setPreferredSize(new Dimension(600,400));
//	      this.setBackground(new Color(40,240,120));
	      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	      setupComponents();
	}
	public void setupComponents(){
		text1 = new JLabel("X select your location.");
		
		button1 = new JButton("New Game");
		for(int i=0;i<playButtons.length;i++){
			String rowText = "第"+(i+1)+"行";
			for(int j=0; j<playButtons.length; j++){
				button2 = new JButton(rowText+"第"+(j+1)+"列");
				playButtons[i][j]=button2;
			}
		}
		JPanel panel1 = new JPanel();
		panel1.setSize(500, 100);
		panel1.setBackground(new Color(255,255,0));
		panel1.setPreferredSize(new Dimension(50, 50));
		panel1.add(text1);
		add(panel1,BorderLayout.NORTH);
		
		JPanel panel2 = new JPanel();
		panel2.setSize(500, 300);
		panel2.setPreferredSize(new Dimension(600, 100));
		panel2.setLayout(new GridLayout(3,3));
		panel2.setBackground(new Color(0,0,0));
		for (int i = 0 ;i<playButtons.length;i++) {
			for(int j = 0 ;j<playButtons[i].length;j++){
				JButton btn = (JButton) playButtons[i][j];
				panel2.add(btn);
			}
		}
		add(panel2,BorderLayout.CENTER);
		
		JPanel panel3 = new JPanel();
		panel3.setSize(500, 100);
		panel3.setBackground(new Color(40,240,120));
		panel3.add(button1);
		add(panel3,BorderLayout.SOUTH);
		
		
		
		
	}
	public void showGame() {
	      this.setVisible(true);
	   }

}
 